package comlibs.huydung
{
	import flash.events.Event;
	import flash.net.FileFilter;
	import flash.net.FileReference;
	
	public class FileChooser
	{
		public static var fileRef:FileReference;
		
		public static const IMAGE_TYPES:Array = new Array(
			new FileFilter("Images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg; *.jpeg; *.gif; *.png")
		);
		
		public static const TEXT_TYPES:Array = new Array(
			new FileFilter("Text Files (*.txt, *.rtf)", "*.txt; *.rtf")
		);
		public static const DOC_TYPES:Array = new Array(
			new FileFilter(
			"Document Files (*.doc, *.docx, *.pdf, *.ppt, *.xls, *.pptx, *.xlsx, *.odt, *.ods, *.odp)",
			"*.doc; *.docx; *.pdf; *.ppt; *.xls; *.pptx; *.xlsx; *.odt; *.ods; *.odp")
		);
		
		public static const ARCHIVE_TYPES:FileFilter = new FileFilter("Archive files (*.zip, *.rar, *.tar.gz)", "*.zip; *.rar; *.tar.gz")
		
		public static const ALL_TYPES:Array = new Array(IMAGE_TYPES, TEXT_TYPES, DOC_TYPES, ARCHIVE_TYPES);	
		
		public static function run(types:Array, selectCallback:Function = null, completeCallback:Function = null):Boolean{
			fileRef = new FileReference();
			if(selectCallback != null){
				fileRef.addEventListener( Event.SELECT, selectCallback );
			}
			if(completeCallback != null){
				fileRef.addEventListener( Event.COMPLETE, completeCallback );
			}
			return fileRef.browse(types);
		}

	}
}